package com.tedu.doctors.service.impl;

import com.tedu.doctors.mapper.DoctorMapper;
import com.tedu.doctors.pojo.dto.DoctorParam;
import com.tedu.doctors.pojo.dto.DoctorQuery;
import com.tedu.doctors.pojo.entity.Doctor;
import com.tedu.doctors.pojo.vo.DoctorVO;
import com.tedu.doctors.service.DoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;
    @Override
    public List<DoctorVO> selectDoctor(DoctorQuery doctorQuery) {
        log.debug("查询医生业务,参数:{}",doctorQuery);
        List<DoctorVO> list = doctorMapper.selectDoctor(doctorQuery);
        System.out.println(list);
        return list;
    }

    @Override
    public void savaDoctor(DoctorParam doctorParam) {
        log.debug("保存医生业务,参数:{}",doctorParam);
        Doctor doctor = new Doctor();
        BeanUtils.copyProperties(doctorParam,doctor);
            //锁住id需要判断是新增还是修改操作
        if(doctor.getDoctorId()==null){
            doctor.setCreateTime(new Date());
            //新增用户
            doctorMapper.insert(doctor);
        }else{
            //更新用户
            doctor.setUpdateTime(new Date());
            doctorMapper.update(doctor);
        }
    }

    @Override
    public void deleteDoctor(Long doctorId) {
        log.debug("删除医生业务,参数:{}",doctorId);
        doctorMapper.deleteById(doctorId);
    }
//
//    @Override
//    public void updateDoctor(Long doctorId) {
//    }
}
